package com.anrongtec.zcpt.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;

/**
 * 基础工具类
 * 
 * @ClassName: IUtil
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author dongtianhao
 * @date 2016年7月8日 下午3:24:47
 *
 */
@SuppressLint("NewApi")
public class IUtil {
	/**
	 * 
	 * @Title: isApkDebugable @Description:
	 *         Android应用程序中来判断当前应用是否处于debug状态 @param @param
	 *         context @param @return 设定文件 @return boolean 返回类型 @throws
	 */
	public static boolean isApkDebugable(Context context) {
		try {
			ApplicationInfo info = context.getApplicationInfo();
			return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
		} catch (Exception e) {

		}
		return false;
	}

	public Bitmap drawable2Bitamp(Drawable drawable) {
		int w = drawable.getIntrinsicWidth();
		int h = drawable.getIntrinsicHeight();
		Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
				: Bitmap.Config.RGB_565;
		Bitmap bitmap = Bitmap.createBitmap(w, h, config);
		// 注意，下面三行代码要用到，否在在View或者surfaceview里的canvas.drawBitmap会看不到图
		Canvas canvas = new Canvas(bitmap);
		drawable.setBounds(0, 0, w, h);
		drawable.draw(canvas);
		return bitmap;
	}

}
